import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/login',
      name: 'Login',
      icon: 'search',
      meta: {
        title: '登录页面',
        icon: 'search',
        isKeepAlive: true
      },
      component: () => import('../pages/Login/Login')
    },
    {
      path: '/register',
      name: 'Register',
      meta: {
        title: '注册页面',
        isKeepAlive: true
      },
      component: () => import('../pages/Register/Register')
    },
    {
      path: '/',
      name: 'Home',
      icon: 'home-o',
      meta: {
        title: '首页',
        showFooter: true
      },
      component: () => import('../pages/Home/Home')
    },
    {
      path: '/regulations',
      name: 'Regulations',
      icon: 'home-o',
      meta: {
        title: '政策',
        showFooter: true
      },
      component: () => import('../pages/Regulations/Regulations')
    },
    {
      path: '/regulations-section',
      name: 'RegulationsSection',
      icon: 'home-o',
      meta: {
        title: '工程建设法规汇编'
      },
      component: () => import('../pages/RegulationsSection/RegulationsSection')
    },
    {
      path: '/regulations-details',
      name: 'RegulationsDetails',
      icon: 'home-o',
      meta: {
        title: '工程建设法规汇编'
      },
      component: () => import('../pages/RegulationsDetails/RegulationsDetails')
    },
    {
      path: '/search',
      name: 'Search',
      icon: 'home-o',
      meta: {
        title: '法规'
      },
      component: () => import('../pages/Search/Search')
    },
    {
      path: '/profile',
      name: 'Profile',
      icon: 'home-o',
      meta: {
        title: '我的',
        showFooter: true,
        isKeepAlive: true
      },
      component: () => import('../pages/Profile/Profile')
    },
    {
      path: '/collect',
      name: 'Collect',
      icon: 'home-o',
      meta: {
        title: '收藏',
        isKeepAlive: true
      },
      component: () => import('../pages/Collect/Collect')
    },
    {
      path: '/browse',
      name: 'Browse',
      icon: 'home-o',
      meta: {
        title: '浏览',
        isKeepAlive: true
      },
      component: () => import('../pages/Browse/Browse')
    },
    {
      path: '/profileDetail',
      name: 'ProfileDetail',
      meta: {
        title: '我的资料',
        isKeepAlive: true
      },
      component: () => import('../pages/ProfileDetail/ProfileDetail')
    },
    {
      path: '/',
      redirect: '/',
      hidden: true
    },
    {
      path: '*',
      name: 'NotFound',
      hidden: true,
      meta: {
        title: '404'
      },
      component: () => import('../pages/404/NotFound')
    }
  ],
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      new Promise((resolve) => {
        setTimeout(() => {
          resolve({ x: 0, y: 1 })
        }, 500)
      })
    }
  }
})
